package cn.sunxyz.aop.aspect;

/**
 * Created by yangrd on 2017/5/25.
 */
public abstract class AbstractInvocationHandler implements InvocationHandler {

    protected InvocationHandler handler;

    @Override
    public void setHandler(InvocationHandler handler) {
        this.handler = handler;
    }

    @Override
    public Object handlerInvocation(Invocation invocation) throws Throwable {
        return createProxyObj(invocation);
    }

    protected Object createProxyObj(Invocation invocation) throws Throwable {
        if (handler != null) {
            return handler.handlerInvocation(invocation);
        }
        return invocation.proxy.invokeSuper(invocation.obj, invocation.args);
    }
}
